<?php
$section = 'gallery';
$titre = _LB_GALLERY_MANAGEMENT;
$smarty->assign("titre", $titre);

//get object ID
$id = Request::getIntNumber('id');
$pid = Request::getIntNumber('pid');
$act = Request::getIntNumber('act');

//get back link
$backlink = Session::getBackLink($section,"list/?");

$album = new Album();
if(!$id || !$album->get($id))
{
    redirect($backlink);		
}

$album_gallery = new Album_Gallery();
if($pid)
{
	if(!$album_gallery->get($pid))
		redirect($backlink);
}

//if action = UPDATE or CREATE
if ($act == ACT_VALID_EDIT)
{
    $album_gallery->ID_ALBUM = $id;
	$album_gallery->TITLE = trim(Request::get('TITLE'));
	$album_gallery->CONTENT = trim(Request::get('CONTENT'));
    $album_gallery->DISABLED = Request::getNumber('DISABLED');
	
	if ($album_gallery->validateInput())
	{
		$album_gallery->save();

		redirect($backlink);
	}

}
//create cfer
$cfer = new Cfer(array(
	_LB_ACCUEIL => Utils::getHomeLink(),
	_LB_GALLERY_MANAGEMENT => $backlink,
	($pid == 0? _LB_ADD_GALLERY_PHOTO : _LB_EDIT_GALLERY_PHOTO) => Utils::getCurrentLink() ));

//if validate is false, display form again
$smarty->assign('cfer', $cfer);
$smarty->assign('album', $album);
$smarty->assign('album_gallery', $album_gallery);
$smarty->assign('backlink', $backlink);
$smarty->display('gallery_photo_form.html');